package com.hw.protocol.tool.decode.hb;

import com.hw.protocol.tool.model.entity.hb.CathodeProtection;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author : lihy
 * @date : 2023/11/3 10:55
 * description: 阴极保护实时数据解码器
 */

public class CathodeProtectionDecode {

    private ByteBuf dataBuf;

    private CathodeProtection cp;

    public CathodeProtectionDecode(String devSerial, byte[] data) {
        this.dataBuf = Unpooled.wrappedBuffer(data);
        this.cp = new CathodeProtection();
        cp.setDevSerial(devSerial);
    }

    public CathodeProtection buildObject(){
        cp.setTime(DecodeUtil.getTime(dataBuf));
        cp.setPowerOnPotential(dataBuf.readFloatLE());
        cp.setPowerOffPotential(dataBuf.readFloatLE());
        cp.setNaturePotential(dataBuf.readFloatLE());
        cp.setAcInterferencePotential(dataBuf.readFloatLE());
        cp.setAcInterferenceCurrent(dataBuf.readFloatLE());
        cp.setDcInterferencePotential(dataBuf.readFloatLE());
        cp.setDcInterferenceCurrent(dataBuf.readFloatLE());
        cp.setAnodePotential(dataBuf.readFloatLE());
        cp.setAnodeCurrent(dataBuf.readFloatLE());


        dataBuf.release();

        return cp;
    }
}
